package com.zkdcloud.repository;

import com.zkdcloud.domain.Order;
import com.zkdcloud.dto.QueryOrderBean;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.SQL;
import org.jfaster.mango.plugin.page.Page;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * order Dao
 *
 * @author zk123
 * @version 2018/5/24
 */
@DB(table = "t_order")
@Repository
public interface OrderDao {
    String COLUMNS = "id,cart_id,business_id,user_id,status,origin_price," +
            "discount_price,total_price,consignee,phone,address,pay_method,remark,book_time,create_time";

    /**
     * 添加订单
     *
     * @param order order
     */
    @SQL("insert into #table("+COLUMNS+") values(:id,:cartId,:businessId,:userId,:status,:originPrice,:discountPrice,:totalPrice," +
            ":consignee,:phone,:address,:payMethod,:remark,:bookTime,:createTime)")
    void add(Order order);

    /**
     * 修改订单状态
     *
     * @param id id
     * @param status status
     */
    @SQL("update #table set status = :2 where id = :1")
    void changeStatus(String id,String status);

    /**
     * 根据用户获取订单
     *
     * @param uid uid
     * @return orderList
     */
    @SQL("select * from #table where user_id = :1 order by create_time desc")
    List<Order> getAllByUid(String uid);

    /**
     * 获取商家订单
     *
     * @param bid bid
     * @return order
     */
    @SQL("select * from #table where business_id = :businessId " +
            " #if(:status != null) and status = :status #end" +
            "order by create_time desc")
    List<Order> getAllByBid(QueryOrderBean queryOrderBean, Page page);

    /**
     * 根据id 获取
     *
     * @param id id
     * @return order
     */
    @SQL("select * from #table where id = :1")
    Order getOne(String id);
}
